<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>附件上传</title>
		<link rel="stylesheet" type="text/css" href="../js/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../css/common.css" />
		<script src="../js/jquery.min.js"></script>
		<script src="../js/layui/layui.js"></script>
		<script src="../js/common.js"></script>
	</head>

	<body style="padding: 50px;">
		<div class="layui-upload-2 layui-btn-group">
			<span id="test8" class="upload-file layui-btn layui-btn-primary">请选择文件</span>
			<button id="test9" class="upload-all layui-btn layui-btn-primary" type="button"><i class="iconfont icon-upload"></i>开始上传</button>
		</div>

		<script type="text/javascript">
			//选完文件后不自动上传
			upload({
				elem: '#test8',
				url: '/upload/',
				auto: false,
				bindAction: '#test9',
				done: function(res) {
					console.log(res)
				},
				error: function(res) {
					console.log(res)
				}
			});
		</script>

		<br />
		<hr /><br />

		<div id="upload-1"></div>

		<div>
			<br /><br />
			<button onclick="console.log(xxx.inst.config.dataNew);">当前缩列图文件信息</button>
		</div>

		<script type="text/javascript">
			var xxx = uploadPreview({
				elem: '#upload-1',
				url: '../js/upload.json', //上传地址
				accept: 'file', //文件类型
				exts: 'jpg|png|gif|bmp|jpeg|pdf', //文件后缀
				//size: 1000, //上传单个文件大小限制
				number: 5, //文件个数限制
				multiple: true, //允许多文件上传
				dataOld: [{ //现有文件
					url: 'https://www.baidu.com/img/bd_logo1.png',
					name: 'img.png'
				}, {
					url: 'https://bable2000.gitee.io/layui-update/img/PDF.pdf',
					name: 'PDF.pdf'
				}],
				data: {
					sessionId: 'sessionV',
					dicName: 'dicV',
					fieldId: 'fieldV',
					id: 'idV',
					accept: 'acceptV'
				},
				done: function(res, index) {
					console.log('上传成功的单项', $('#upload-1').find('#upload-' + index))
					if(res.code == 200) { //上传成功
						//返回文件信息致dataNew
						return {
							"name": "PDF.pdf",
							"url": "img/PDF.pdf"
						};
					} else {
						return false
					}
				},
				delete: function(index, dalFn) {
					console.log('要删除的单项', $('#upload-1').find('#upload-' + index));
					dalFn(); //删除成功后的处理函数
				},
				error: function(index) {
					console.log(index + '上传失败');
				}
			});

			setTimeout(() => {
				console.log(xxx)
			}, 1000)
		</script>
	</body>

</html>